package com.ghsc.ghxc.jsb.ui.my.activity

import androidx.lifecycle.MutableLiveData
import com.cn.appcore.base.BaseViewModel
import com.cn.appcore.ext.executeListResponse
import com.cn.appcore.ext.executeResponse
import com.cn.appcore.http.bean.BaseListResponse
import com.cn.appcore.http.bean.BaseResponse
import com.ghsc.ghxc.jsb.api.ApiMarket
import com.ghsc.ghxc.jsb.ui.my.bean.AddressDetailBean
import com.ghsc.ghxc.jsb.ui.my.bean.AddressJsonBean
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * 项目：GuoHuaJsb
 * 包名：com.ghsc.ghxc.jsb.ui.my.activity
 * 类名：AddressViewModel
 * 创建时间：2024/4/24 20:06
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
class AddressViewModel : BaseViewModel() {



    /**
     * 收货地址
     */
    val onAddressListData: MutableLiveData<List<AddressDetailBean>> = MutableLiveData()
    fun onAddressListMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onAddressListData(paras) }
            executeListResponse(
                response,
                { onAddressListData.value = response.data},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }





    //收货地址 add
    val onShouhuoSiteAddData: MutableLiveData<BaseResponse<Any>> = MutableLiveData()
    fun onShouhuoSiteAddMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onShouhuoSiteAddData(paras) }
            executeResponse(
                response,
                { onShouhuoSiteAddData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }

    //收货地址 update
    val onShouHuositeUpdData: MutableLiveData<BaseResponse<Any>> = MutableLiveData()
    fun onShouHuositeUpdMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onShouHuositeUpdData(paras) }
            executeResponse(
                response,
                { onShouHuositeUpdData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }



    /**
     * 删除地址
     */
    var deleteAddressResult = MutableLiveData<BaseResponse<Any>>()
    fun deleteAddress(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onDeleteAddress(paras) }
            executeResponse(
                response,
                { deleteAddressResult.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }


}